# -*- coding: utf-8 -*-
'''
	事件管理
'''
import uvicorn
from fastapi import FastAPI
from typing import Callable

app = FastAPI()

def startup(app: FastAPI) -> Callable:
    """
    FastApi 启动完成事件
    :param app: FastAPI
    :return: start_app
    """
    async def app_start() -> None:
        print("应用已启动")
         
    return app_start

def stopping(app: FastAPI) -> Callable:
    """
    FastApi 停止事件
    :param app: FastAPI
    :return: stop_app
    """
    async def stop_app() -> None:
        print("应用已停止")
        pass
       
    return stop_app


app.add_event_handler("startup", startup(app))
app.add_event_handler("shutdown", stopping(app))

@app.get("/")
def index():
    return "Hello world!"

if __name__ == '__main__':

    uvicorn.run(
        app     = 'example04-事件:app', 
        host    = "0.0.0.0", 
        port    = 8080, 
        reload  = True
    )